<template>
	<view>
		<view class="d-kuan-juzhong pc-yincang">
    	    <view class="d-kuan  pc-header ">
					<uv-row customStyle="margin-top: 0px" :gutter="10">
						<uv-col span="2">
							<view class="d-logo d-zuo d-you-20" style="display: flex;width: 80%;" @click="shouye">
								<image :src="wwwData && wwwData.setting && wwwData.setting.config && wwwData.setting.config.logo" mode="aspectFit" style="max-height: 50px;margin-top: 3px;align-self: flex-start;"></image>
							</view>
						</uv-col>
						<uv-col span="7">
							<!--搜索-->
							<view class="pc-neikuang-20">
								<view class="d-sousuo d-zuo">
									<uv-search placeholder="搜索" @search="handleSearch" v-model="localSearch" @custom="handleSearch" style="width: 100%;background-color: rgba(255, 255, 255, 0.7)"></uv-search>
								</view>
							</view>
							<!--搜索-->
						</uv-col>
						<uv-col span="3">
							<!--登录-->
								<view v-if="yidenglu ==0" class="d-denglu d-juzhong-kuan d-zuo d-zuo-10" style="display: flex; ">
									<view class="d-you-10" @click="dengluzhi">
										<uv-icon name="/static/img/fabu2.png" size="30px"></uv-icon>
									</view>
									<uv-button  type="primary" custom-style="borderRadius: 40rpx;background-color: #02c7b6; border: 1px solid #02c7b6" size="small" @click="dengluzhi">登录 / 注册</uv-button>
								</view>
								<view v-else class="d-denglu d-juzhong-kuan d-zuo d-zuo-10" style="display: flex; ">
									<view class="d-you-10" @click="fabu">
										<uv-icon name="/static/img/fabu2.png" size="30px"></uv-icon>
									</view>

									<view class="d-you-10" @click="url('xiaoxi',1)">
										<uv-icon name="/static/img/xiaoxi3.png" size="30px"></uv-icon>
									</view>
									<view class="d-xiala-0" @mouseenter="showDropdown = true" @mouseleave="showDropdown = false">
										<!--uv-icon @click="getU" size="20px" :name="touxiang" :label="name1" labelSize="16px" class="d-you-10 d-yuanjiao-50" space="10px"></uv-icon-->
										<view class="d-buhuanhang">
											<uv-image :src="touxiang" width="25px" height="25px" shape="circle"></uv-image>
											<text class="d-shang-5 d-zuo-10 d-wenzi-14  " style="color: #717171; "> {{ name1 }} </text>

										</view>
										<view class="d-xiala-1" v-show="showDropdown">
											<uv-icon  @click="getU" size="20px" name="account" label="我的" labelSize="16px" class=" d-shangxia-15"></uv-icon>
											


											<uv-icon  @click="geren(uid)" size="20px" name="home" label="个人主页" labelSize="16px" class=" d-shangxia-15"></uv-icon>
											<!--uv-icon  @click="url('woke')" size="20px" name="play-circle" label="我的课程" labelSize="16px" class=" d-shangxia-15"></uv-icon-->
											<uv-icon  @click="shezhi_url" size="20px" name="setting" label="设置" labelSize="16px" class=" d-shangxia-15"></uv-icon>
										    <uv-icon size="20px" name="minus-circle" label="退出" labelSize="16px" @click="tuichu" class="d-shangxia-15"></uv-icon>
										</view>
									</view>

								</view>

								<!--登录-->
						</uv-col>
					</uv-row>
					
			</view>
		    <view v-if="denglu_xianshi==1" class="denglu" @click="handleDengluClick">
				<view class="denglu_2" @click.stop="noop">
					<view class="d-kuan">
						<view class="d-baifen-50 d-zuo ">
							<view class="title">
								<view>Hello！<br>欢迎来到{{ wwwData && wwwData.setting && wwwData.setting.config.SITE_NAME }}</view>
							</view>
							<view class="form">
								<view class="tab">
									<view v-if="phone == 1" :class="loginType==1? 'select type1' : 'type1'" @click="loginType=1">快捷登录</view>
									<view  :class="loginType==2? 'select type2' : 'type2'" @click="loginType=2">账号登陆</view>
									<view  :class="loginType==3? 'select type2' : 'type3'" @click="loginType=3">注册</view>
								</view>
								<view class="inputs">
									<view v-if="loginType==1" class="account">
										<view>+86</view> <input type="number" v-model="yonghu.phone" :adjust-position="false"
											placeholder="手机号" />
									</view>
									<view v-if="loginType==2" class="account">
										 <input type="text" v-model="yonghu.username" :adjust-position="false"
											placeholder=" 账号" />
									</view>

									<view v-if="loginType==1" class="vcode">
										<input type="number" v-model="yonghu.vcode" :adjust-position="false" placeholder="请输入验证码" />
										<text v-if="vcodeTime==0" style="color:#16afa8" @click="postRenzhengma">获取验证码</text>
										<text v-else style="color:#ccc">重新获取({{vcodeTime}}s)</text>
									</view>
									<view  v-if="loginType==2" class="vcode">
										<input type="password" v-model="yonghu.password" :adjust-position="false" placeholder="请输入密码" />
									</view>
									
									
									<!--账号登录-->
									<view v-if="loginType==3 && username == 1" class="vcode">
										 <input type="text" v-model="yonghu.username" :adjust-position="false"
											placeholder=" 账号" />
									</view>
									<view v-if="loginType==3 && phone == 1" class="vcode">
										<view class="d-you-10">+86</view> <input type="number" v-model="yonghu.phone" :adjust-position="false"
											placeholder="手机号" />
									</view>
									<view  v-if="loginType==3 && email == 1" class="vcode">
										<input type="text" v-model="yonghu.email" :adjust-position="false" placeholder="请输入邮箱" />
									</view>
									<view  v-if="loginType==3" class="vcode">
										<input type="password" v-model="yonghu.password" :adjust-position="false" placeholder="请输入密码" />
									</view>
									<view v-if="loginType==3 && code == 1" class="vcode">
										<view class="d-you-10" >
											<!--图片认证码-->
											<image @click="getRenzhengma" :src="get_rzm" mode="aspectFill" class="erweima" style="width: 80px; height: 40px;"></image>
										</view> 
										<input type="text" v-model="yonghu.code" :adjust-position="false"
											placeholder="认证码" />
									</view>
								</view>
								<view v-if="loginType==1" class="button">
									<view @click="zhuce">
										立即登录
									</view>
								</view>
								<view v-if="loginType==2" class="button">
									<view @click="denglu_data">
										立即登录
									</view>
								</view>
								<view v-if="loginType==3" class="d-juzhong d-zitiyanse-hongse">
									<view @click="zhuce_data">
										新用户注册
									</view>
								</view>
								<view v-if="loginType==1" class="tip">
									<text>未注册的手机号验证后即可完成注册</text>
								</view>
								<view v-if="loginType==1" class="pact">
									<radio :checked="pactChecked" activeBackgroundColor="#3ba662" activeBorderColor="#3ba662"
										borderColor="#3ba662" color="#fff" @click="pactChange" />
									<view>我已阅读并同意<text @click="toPact">《用户协议》</text>和<text @click="toPact">《隐私协议》</text></view>
								</view>
							</view>
						</view>
						<view class="d-baifen-50 d-you huise">
							<view class="d-kuan">
								<view class="d-neikuang-10 ">
									<view class="d-juzhong d-shangxia-30"> {{ wwwData && wwwData.setting && wwwData.setting.config.SITE_NAME }} </view>
									<view v-if="wwwData && wwwData.setting && wwwData.setting.erweima && wwwData.setting.erweima.id == 1">
										<view class="d-juzhong d-shangxia-30 d-erweima">
											<view v-if="weixin_login==1" id="pc_weixin"></view>
											<view v-if="weixin_login==2" >
												<image :src="gongzhonghao_erweima" mode="aspectFill" class="erweima" style="width: 180px; height: 180px;"></image>
											</view>
										    <!--uv-qrcode ref="qrcode" size="150px" value="https://duixin.cc" :canvas-config="{ willReadFrequently: true,antialias: true }"></uv-qrcode-->
										</view>
										<view v-if="weixin_login==1" class="d-juzhong d-shangxia-30"> <uv-icon name="weixin-fill" color="#000000" label="微信登录" size="28"></uv-icon> </view>
										<!--view v-if="weixin_login==2" class="d-juzhong d-shangxia-30"> <uv-icon name="weixin-fill" color="#ff0000" labelColor="#ff0000" label="关注后请点击登录" size="28" @click="get_url_gongzhonghao(gongzhonghao_erweima)"></uv-icon> </view-->


										<view class="d-kuan"> 
										    <view class="form">
												<view class="tab">
													<!--view :class="weixin_login==1? 'select type1' : 'type1'" @click="get_weixin">微信登录</view>
													<view :class="weixin_login==2? 'select type2' : 'type2'" @click="get_gongzhonghao">关注公众号</view-->
												</view>
											</view>
										</view>
								    <!--view class="d-juzhong d-shangxia-30"> 登录方法 </view-->
								    </view>
									<view v-else>
										<view class="d-juzhong d-shangxia-30 d-erweima">
											<uv-qrcode ref="qrcode" size="150px" :value="wwwData ? 'https://' + wwwData.domain : ''"></uv-qrcode>

										</view>
										<view class="d-juzhong d-shangxia-30"> <uv-icon name="grid" color="#000000" label="访问手机二维码" size="28"></uv-icon> </view>

										

									</view>
								</view>

							</view>

    	                </view>


					</view>
				</view>



			</view>
			<!--view class="d-kuan d-buhuanhang">
				<view class="d-logo d-zuo d-you-10" @click="shouye" style="height: 80rpx;">

				</view>
				<view class="d-kuan">
					<uv-tabs :list="daohang_data" @click="daohang_click" lineColor="#000000"></uv-tabs>

				</view>

			</view-->						
			


		</view>
		<view v-if="isHomePage" class="d-kuan-baifen-70-cm h5-yincang" style="background-color: #f3f3f3;">
			<view class="d-kuan">
				<view class="d-zuoyou-neikuang-10 d-neishang-3">
					<view class="d-buhuanhang">
						<!-- 搜索 -->
						<view class="d-kuan-60 d-neirong-juzhong" @click="shouye" style="display: flex; align-items: center; justify-content: center;">
							<image @click="go_shouye" mode="aspectFill" :src="wwwData && wwwData.setting && wwwData.setting.config && wwwData.setting.config.yidonglogo" class="d-yuanjiao-10 d-img-35 " style=""></image>
						</view>
						<view class="d-kuan d-shang-2 d-zuo-5 d-you-5">
							<!--搜索-->
							<view class="d-sousuo d-zuo">
								<uv-search placeholder="搜索"  bgColor="#ffffff" @search="handleSearch" v-model="localSearch"  @custom="handleSearch" style="width: 100%"></uv-search>
							</view>
							<!--搜索-->
						</view>
						<!--view class="d-kuan-60 d-box" style="display: flex; align-items: center; justify-content: center;">
							<image @click="go_xiaoxi" mode="aspectFill" src="/static/img/xiaoxi3.png" class="d-yuanjiao-10 d-img-35 " style="" ></image>
						</view-->
					</view>
				</view>
			</view>
			<view class="d-kuan">
				<uv-tabs v-if="isSouPage" :list="sou_daohang" :current="1" @click="sousuo_daohang" lineColor="#07bfa6" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;"></uv-tabs>
				<uv-tabs v-else :list="list_daohang" :current="xuanzezhi"  @click="click_daohang" lineColor="#07bfa6"  itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;"></uv-tabs>
			    
			</view>

		</view>


	</view>



</template>

<script>
    //引入api
    import Api from '@/utils/api.js';
	//引入get和post集成
	import { getRequest,postRequest } from '@/utils/wxRequest.js'
    // 可以选择直接导入getWwwData方法，也可以使用全局挂载的方法
    import { getWwwData } from '@/utils/www_api.js';
export default {
	beforeUnmount() {
		// 组件销毁时清除定时器
		if(this.denglu_timer){
			clearInterval(this.denglu_timer);
		}
	},
    data() {
        return {
			uiddata: {},
        	denglu_xianshi: 0,
		vcodeTime: 0,
		vcodeTimer: null,
		vcode: '', // 添加这行
            account: '', // 定义，也需要添加
		//yidenglu: 0,
		loginType: 1,
		weixin_login: 1,
			xieyizhi:[], //协议值
			denglu_timer: null, // 登录检测定时器
		username: '',
		phone: '',
		email: '',
		name: '',
		password: '',
		password2: '',
            wwwData: null, // 存储首页数据
	yonghu:[{
			username:'',
		    phone:'',
		    email:'',
		    name:'',
		    password:'',
		    password2:'',
			vcode:''
			}],
			pactChecked: false, // 协议勾选状态
			showDropdown: false,
			touxiang:'',
			name1:'',
			daohang_data:[
				{
					id:1,
					name: '推荐',
					icon: 'home',
					active: true,
					url: '/pages/index/index'
				},
				{
					id:2,
					name: '圈子',
					icon: 'home',
					active: false,
					url: '/pages/圈子/index'
				},
				{
					id:3,
					name: '课程',
					icon: 'home',
					active: false,
					url: '/pages/kecheng/index'
				},
			],
			list_daohang: [
				{
					id: 0,
					name: '最新',
					icon: 'home',
					active: true,
					url: '/pages/index/index'
				},
				{
					id: 1,
					name: '推荐',
					icon: 'home',
					active: true,
					url: '/pages/index/index'
				},
				{
					id: 2,
					name: '精华',
					icon: 'home',
					active: false,
					url: '/pages/quan/index'
				},
				{
					id: 3,
					name: '热门',
					icon: 'home',
					active: false,
					url: '/pages/kecheng/index'
				},
				{
					id: 4,
					name: '热评',
					icon: 'home',
					active: false,
					url: '/pages/kecheng/index'
				},
				
				{
					id: 5,
					name: '关注',
					icon: 'home',
					active: false,
					url: '/pages/kecheng/index'
				},
				{
					id: 7,
					name: '收藏',
					icon: 'home',
					active: false,
					url: '/pages/wenda/index'
				},
				{
					id: 8,
					name: '点赞',
					icon: 'home',
					active: false,
					url: '/pages/shouce/index'
				},
				{
					id: 9,
					name: '评论',
					icon: 'home',
					active: false,
					url: '/pages/shouce/index'
				},
				{
					id: 10,
					name: '历史',
					icon: 'home',
					active: false,
					url: '/pages/shouce/index'
				},
			],
			sou_daohang:[
				{
					id: 0,
					name: '首页',
					icon: 'home',
					active: true,
					url: '/pages/index/index'
				},
				{
					id: 1,
					name: '帖子',
					icon: 'home',
					active: true,
					url: '/pages/tiezi/index'
				}
			],

			xuanzezhi:0,
			id:0,
			weixinid:{},
			currentPageUrl: '', // 当前页面的URL
			gongzhonghao_erweima:'',//公众号二维码
			isHomePageData: false, // 存储是否为首页的状态
			zhucexuanxiang:[], //注册选项
			zhuceType: 1, //注册类型 1手机号 2邮箱
			email: 0, //是否注册邮箱
			username: 0, //是否注册用户名
			phone: 0, //是否注册手机号
			get_rzm: '', //获取注册认证码
			code: 0, //是否需要验证码
			localSearch: '', // 本地搜索值，用于双向绑定搜索框
			isSouPage: false, // 是否为搜索页面
        }
    },
	props: {
		dengluxianshi: {
  	  	  type: Number,
  	  	  default: 0,
			validator: (value) => {
      			// 验证值是否为数字或可转换为数字的字符串
      			return !isNaN(Number(value))
            }
  	  	},
		title: {
			type: String,
			default: ''
		},
		search: {
			type: String,
			default: ''
		}
  	},
	// 监听props变化
	watch: {
    	dengluxianshi(newVal) {
    	  this.denglu_xianshi = Number(newVal);
		  ////console.log('dengluxianshi变化:', newVal);
		},
		// 当父组件传递的search prop变化时，更新本地搜索值
		search(newVal) {
		  this.localSearch = newVal;
		}
    },
	computed: {
	  yidenglu() {
	    return (this.$store.state.memberuid && this.$store.state.keycode) ? 1 : 0;
	  },
	  uid() {
	    return this.$store.state.memberuid;
	  },
	  /*touxiang() {
	    return this.$store.state.member? this.$store.state.member.avatar : '';
	  },*/
	  /*name1() {
	const member = this.$store.state.member;
    if (!member) return '';
    return member.name || member.uname || member.username || '';
	    //return this.$store.state.member? this.$store.state.member.name : '';
	  },*/
	    isHomePage() {
            // 返回存储的首页状态
            return this.isHomePageData;
    	}
	},
	mounted() {
		this.sousuo_ye();
        this.checkCurrentPage();
		this.getUrlId();
        // 调用方法获取全局数据
        this.loadWwwData();
        // 初始化注册选项
        this.zhucexiangmu();
		//获取注册认证码
		this.getRenzhengma();
		// 初始化时将search prop值同步到localSearch
		this.localSearch = this.search;
		// 监听denglu_xianshi变化，当弹窗显示时再初始化微信登录
		this.$watch('denglu_xianshi', (newVal) => {
			if (newVal === 1) {
				this.$nextTick(() => {
					this.pc_weixin_denglu();
					this.zhucexiangmu(); //注册选项
				});
			}
		});
		//
		//获取本页的网址
		//const currentUrl = window.location.href;
		//const currentUrl = 'https://q.duixin.cc';
		const currentUrl = window.location.href;
		////console.log('当前页面URL:', currentUrl);
		
		//保存原始URL到wwwurl，不能包含duixin=1
		if(!currentUrl.includes('duixin=1')){
			uni.setStorageSync('wwwurl', currentUrl);
		}
		this.currentPageUrl = currentUrl+'?duixin=1';
		//如果网址里面有&code参数，那么api执行接口
		if (currentUrl.includes('&code=')) {
			// 从URL中提取code参数
			const codeMatch = currentUrl.match(/&code=([^&]+)/);
			if (codeMatch && codeMatch[1]) {
				const code = codeMatch[1];
				//console.log('检测到code参数:', code);
				// 检查是否同时存在?duixin=1参数
				if (currentUrl.includes('?duixin=1') || currentUrl.includes('&duixin=1')) {
					console.log('网址同时包含&code参数和duixin=1参数');
					this.handleWechatCode(code);
				}
				// 调用API执行接口
				
			}
		}
		this.get_uid();
		// 初始化xuanzezhi值
		this.setXuanzezhiByRoute();
		
    },
      methods: {
		//判断是否为搜索页面
		sousuo_ye(){
			const pages = getCurrentPages();
			let isSouPage = false;
			if (pages && pages.length > 0) {
	            const currentPage = pages[pages.length - 1];
	            isSouPage = currentPage.route === 'pages/sou/index';
            }
            this.isSouPage = isSouPage;

		},
		handleSearch(searchValue) {
			console.log('搜索内容:', searchValue);
			// 这里可以添加搜索逻辑
			if (searchValue) {
				//加一个判断，如果搜索内容为空，那么不跳转
				if(searchValue == ''){
					return;
				}
				// 检查当前页面是否为sou/index页面
				const pages = getCurrentPages();
				let isSouPage = false;
				if (pages && pages.length > 0) {
					const currentPage = pages[pages.length - 1];
					isSouPage = currentPage.route === 'pages/sou/index';

				}
				this.isSouPage = isSouPage;
				
				//如果是sou/index页面，不进行跳转，而是触发搜索事件
				if(isSouPage){
					this.$emit('sousuo', searchValue);
				} else {
				// 保持本地搜索值不变，这样搜索后搜索框中仍会显示搜索内容
				    uni.navigateTo({
					    url: '/pages/sou/index?search=' + searchValue
				    });
				}
			}
		}, 
	// 根据当前路由设置xuanzezhi值
	setXuanzezhiByRoute() {
		const pages = getCurrentPages();
		if (!pages.length) return;
		const currentPage = pages[pages.length - 1];
		const route = currentPage.route;
		
		if(route === 'pages/index/index'){
			this.xuanzezhi=0;
		} else if(route === 'pages/quan/index') {
			this.xuanzezhi=1;
		} else if(route === 'pages/zhishi/index') {
			this.xuanzezhi=2;
		} else if(route === 'pages/yingyong/index') {
			this.xuanzezhi=3;
		} else if(route === 'pages/wenda/index') {
			this.xuanzezhi=4;
		} else if(route === 'pages/shouce/index') {
			this.xuanzezhi=5;
		} 
		
		
	},
		// 点击微信二维码
		get_weixin(){
			this.weixin_login=1;
			// 调用API执行接口
			this.pc_weixin_denglu();
		},
		// 点击公众号
		get_gongzhonghao(){
			this.weixin_login=2;
			// 调用API执行接口
			this.pc_gongzhonghao_denglu_api();
		},
	
		// 处理URL中的微信code参数
		handleWechatCode(code) {
			const url = Api.pc_weixin_denglu();
			////console.log('调用微信code处理接口:', url);
			const params = {
				code: code
			}
			var get_data = getRequest(url,params);
			get_data.then(response => {
				////console.log('微信code处理结果:', response.data);
				if(response.data.code == 1){
					uni.setStorageSync('memberuid', response.data.data.member && response.data.data.member.id);
					uni.setStorageSync('member', response.data.data.member);
					uni.setStorageSync('keycode', response.data.data.auth);
							
					this.$store.commit('setMember', response.data.data.member);
					this.$store.commit('setMemberUid', response.data.data.member.id);
					this.$store.commit('setKeycode', response.data.data.auth);
					// 登录成功
					//头像
							this.touxiang = response.data.data.member && response.data.data.member.avatar;
							//昵称
							if(!response.data.data.member && response.data.data.member.name){
								this.name1 = response.data.data.member && response.data.data.member.username;

							} else {
								//昵称
								this.name1 = response.data.data.member && response.data.data.member.name;
							}
					// 显示成功提示
						uni.showToast({
							title: '登录成功',
							icon: 'success',
							duration: 2000
						});
						// 触发登录成功事件
						this.$emit('login-success');
						//wwwurl 里面的网址
						const wwwurl = uni.getStorageSync('wwwurl');
						// 跳转到wwwurl
						//console.log('跳转网址wwwurl',wwwurl);
						// 检查wwwurl是否有效
						if (wwwurl && wwwurl.trim() !== '') {
							// 如果是完整URL，使用浏览器打开而不是应用内跳转
							if (wwwurl.startsWith('http://') || wwwurl.startsWith('https://')) {
								window.location.href = wwwurl;
							} else {
								// 应用内页面路径，使用uni.reLaunch
								uni.reLaunch({ url: wwwurl });
							}
						} else {
							//console.log('wwwurl为空，无法跳转');
							// 可以设置一个默认跳转地址
							uni.reLaunch({ url: '/pages/index/index' });
						}
						
						

				} else {
					// 处理失败逻辑
					uni.showToast({
						icon: 'none',
						title: response.data.msg || '微信登录失败'
					});
					//wwwurl 里面的网址
					const wwwurl = uni.getStorageSync('wwwurl');
					// 跳转到wwwurl
					////console.log('登录失败后跳转网址wwwurl:',wwwurl);
					// 检查wwwurl是否有效
					if (wwwurl && wwwurl.trim() !== '') {
						// 如果是完整URL，使用浏览器打开而不是应用内跳转
						if (wwwurl.startsWith('http://') || wwwurl.startsWith('https://')) {
							window.location.href = wwwurl;
						} else {
							// 应用内页面路径，使用uni.reLaunch
							uni.reLaunch({ url: wwwurl });
						}
					} else {
						////console.log('登录失败后wwwurl为空，无法跳转');
						// 可以设置一个默认跳转地址
						uni.reLaunch({ url: '/pages/index/index' });
					}
				}
				/*if (response && response.data && response.data.code) {
					// 处理成功逻辑
					const data = response.data.data;
					//console.log('微信登录成功，用户信息:', data);
					
					// 保存用户信息到本地storage
					if (data.member) {
						uni.setStorageSync('memberuid', data.member.uid);
						uni.setStorageSync('member', data.member);
						uni.setStorageSync('keycode', data.member.auth);
						
						// 更新Vuex状态
						this.$store.commit('setMember', data.member);
						this.$store.commit('setMemberUid', data.member.uid);
						this.$store.commit('setKeycode', data.auth);
						
						// 显示成功提示
						uni.showToast({
							title: '登录成功',
							icon: 'success',
							duration: 2000
						});
						
						// 触发登录成功事件
						this.$emit('login-success');
					}
				} else {
					// 处理失败逻辑
					uni.showToast({
						icon: 'none',
						title: response.data.msg || '微信登录失败'
					});
				}*/
			}).catch(error => {
				console.error('微信code处理请求失败:', error);
				uni.showToast({
					icon: 'none',
					title: '网络请求失败，请稍后重试'
				});
			});
		},
		// 公众号登录
		pc_gongzhonghao_denglu_api(){
			var url = Api.pc_gongzhonghao_denglu();
			//console.log('调用微信code处理接口:', url);
			
			var get_data = getRequest(url);
			get_data.then(response => {
					if(response.data.code == 1){
						// 二维码
						var erweima = response.data.data && response.data.data.qrcode_url;
						var code_id = response.data.data && response.data.data.code_id;
						// 显示二维码
						this.gongzhonghao_erweima = erweima;
						// 检测登录情况
						this.jiance_denglu(code_id);
					} else {
						// 处理失败逻辑
						uni.showToast({
							icon: 'none',
							title: response.data.msg || '公众号获取失败'
						});
					}
				//console.log('微信code处理结果:', response.data);
			}).catch(error => {
				console.error('微信code处理请求失败:', error);
			});
		},
		//
		get_url_gongzhonghao(code_id){
			//console.log('点击：code_id',code_id);
			this.jiance_denglu(code_id);
			var get_data = getRequest(Api.pc_gongzhonghao_jiance(code_id));
				get_data.then(response => {
					//console.log('登录检测结果公众号:', response);
					if(response.data.code == 1){
						// 登录成功逻辑
						//console.log('登录检测结果公众号:成功逻辑', response.data);
						//获取到接口 response.data && response.data.data && response.data.data.sso 里面的内容
						var sso = response.data.data && response.data.data.sso;
						// sso 里面的内容
						//console.log('sso 里面的内容',sso);
						// 这里可以根据需求添加登录成功后的处理逻辑
						// 如果需要登录成功后停止检测，可以添加：
						// 停止后访问接口
						//this.get_gongzhonghao_denglu_api(); //检测访问
						clearInterval(this.denglu_timer);
						
					} else {
						// 登录未成功，继续检测
					}
				}).catch(error => {
					console.error('微信code处理请求失败:', error);
				});

		},
		// 检测登录
		jiance_denglu(code_id){
			// 先清除之前可能存在的定时器
			if(this.denglu_timer){
				clearInterval(this.denglu_timer);
			}
			
			// 创建新的定时器，每2秒检测一次
			const checkLogin = () => {
				// 检查是否切换到了微信登录，如果是则停止检测
				if(this.weixin_login === 1) {
					//console.log('已切换到微信登录，停止公众号登录检测');
					clearInterval(this.denglu_timer);
					return;
				}
				
				var get_data = getRequest(Api.pc_gongzhonghao_jiance(code_id));
				get_data.then(response => {
					//console.log('登录检测结果公众号:', response);
					if(response.data.code == 1 || response.data.code == 0){
						// 登录成功逻辑
						//console.log('登录检测结果公众号:成功逻辑', response.data);
						var sso = response.data.data && response.data.data.sso;
						// sso 里面的内容
						//console.log('sso 里面的内容',sso[0]);
						//this.get_denglu_sso(sso[0]);//访问sso 里面的内容
						this.get_denglu_sso_data(response.data.data);
						

						// 这里可以根据需求添加登录成功后的处理逻辑 123
						// 如果需要登录成功后停止检测，可以添加：
						// 停止后访问接口
						//this.get_gongzhonghao_denglu_api();//成功登录接口
						clearInterval(this.denglu_timer);
						
					} else {
						// 登录未成功，继续检测
					}
				}).catch(error => {
					console.error('微信code处理请求失败:', error);
				});
			};
			
			// 立即执行一次检测
			//checkLogin();
			// 设置定时器，每4秒执行一次
			this.denglu_timer = setInterval(checkLogin, 4000);
		},
		//访问获取到的接口
		get_denglu_sso(sso_url){
			////console.log('1：扫描成功，获取sso，并且访问了')
			var get_data = getRequest(sso_url);
			//this.get_gongzhonghao_denglu_api();//成功登录接口
			get_data.then(response => {
				if(response.code == 1){
					//
					this.get_gongzhonghao_denglu_api();//成功登录接口
					////console.log('2：扫描成功，获取sso，并且访问了')
				}
			})
		},
		get_denglu_sso_data(data){
			uni.showToast({
				title: '登录成功',
				icon: 'success',
				duration: 2000
			});
			uni.setStorageSync('memberuid', data.member && data.member.id);
			uni.setStorageSync('member', data.member);
			uni.setStorageSync('keycode', data.auth);
			
			this.$store.commit('setMember', data.member);
			this.$store.commit('setMemberUid', data.member.id);
			this.$store.commit('setKeycode', data.auth);
			//this.yidenglu = 1;
			this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
			this.$emit('login-success'); // 添加这行
			// 强制刷新
			uni.navigateBack({
				delta: 1
			});
			// 登录成功逻辑
			//console.log('登录检测结果:111111111111111111111111111111111111111');
			// 这里可以根据需求添加登录成功后的处理逻辑
			// 如果需要登录成功后停止检测，可以添加：
			clearInterval(this.denglu_timer);
		},
		// 公众号登录
		get_gongzhonghao_denglu_api(){
			// 调用接口
			var url = Api.get_gongzhonghao_denglu();
			//console.log('调用微信code处理接口的返回结果:', url);
			var get_data = getRequest(url);
			get_data.then(response => {
				if(response.data.code == 1){
					// 显示登录成功
					uni.showToast({
						title: '登录成功',
						icon: 'success',
						duration: 2000
					});
					uni.setStorageSync('memberuid', response.data.data.member && response.data.data.member.id);
					uni.setStorageSync('member', response.data.data.member);
					uni.setStorageSync('keycode', response.data.data.auth);

					this.$store.commit('setMember', response.data.data.member);
					this.$store.commit('setMemberUid', response.data.data.member.id);
					this.$store.commit('setKeycode', response.data.data.auth);
					//this.yidenglu = 1;
					this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
					this.$emit('login-success'); // 添加这行

					// 登录成功逻辑
					//console.log('登录检测结果:', response.data);
					// 这里可以根据需求添加登录成功后的处理逻辑
					// 如果需要登录成功后停止检测，可以添加：
					clearInterval(this.denglu_timer);
					// 停止后访问接口
					//this.get_gongzhonghao_denglu_api();
				} else {
					// 登录未成功，继续检测
					uni.showToast({
						icon: 'none',
						title: response.data.msg || '登录未成功'
					});
				}
			}).catch(error => {
				console.error('微信code处理请求失败:', error);
			});
		},
		
		// PC微信登录
		pcweixinlogin(weixinid){
			// 检查容器元素是否存在
			const container = document.getElementById('pc_weixin');
			if (!container) {
				console.error('微信登录容器元素不存在');
				return;
			}
			// 检查是否已加载微信登录脚本
			if (window.WxLogin) {
				this.initWxLogin(weixinid);
				return;
			}
			const script = document.createElement('script')
			script.src = 'https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js'
			script.onload = () => {
				this.initWxLogin(weixinid);
			}
			script.onerror = () => {
				console.error('微信登录脚本加载失败');
			}
			document.head.appendChild(script)
		},
		
		// 初始化微信登录实例
		initWxLogin(weixinid) {
			const container = document.getElementById('pc_weixin');
			if (!container) {
				console.error('微信登录容器元素不存在');
				return;
			}
			//打印
			////console.log('网址：',this.currentPageUrl);
			new WxLogin({
				self_redirect: false,
				id: "pc_weixin",
				appid: weixinid.openid,
				scope: "snsapi_login",
				redirect_uri: encodeURIComponent(this.currentPageUrl),
				state: '0',
				style: "black",
				href: "data:text/css;base64,LmltcG93ZXJCb3ggLnFyY29kZSB7d2lkdGg6IDE4MHB4ICFpbXBvcnRhbnQ7aGVpZ2h0OiAxODBweCAhaW1wb3J0YW50O21hcmdpbi10b3A6IDExMHB4O30KLmltcG93ZXJCb3ggLnRpdGxlIHtkaXNwbGF5OiBub25lO30KLmltcG93ZXJCb3ggLmluZm8ge2Rpc3BsYXk6IG5vbmU7fTtAcWxvZ2luX21vZCB7dGV4dC1hbGlnbjogY2VudGVyO21hcmdpbi10b3A6IDExMHB4O30KLnFsb2dpbl9tb2Qge3RleHQtYWxpZ246IGNlbnRlcjttYXJnaW4tdG9wOiAxMTBweDt9"
			});
		},
		generateState(weixinid){
			//
			const data = {
				action: 'callback',
				name: 'weixin',
				type: 'login',
				back: weixinid.url
			}
             ////console.log('微信回调',Math.random().toString(36).substring(2, 10));
			 //return Math.random().toString(36).substring(2, 10);
			 var get_data = getRequest(Api.pc_weixin_denglu(),data);
			var res;
			get_data.then(duixin_data => {
				res = duixin_data;
				if(res.data.code) {
					
					////console.log('微信返回',res.dat);
				} else {
					/*uni.showToast({
						icon: 'none',
						title: '获取失败，请稍后重试'
					});*/
				}
			})
		},
		// 点击微信登录
		pc_weixin_denglu(){
			////console.log('点击微信登录');
			var get_data = getRequest(Api.pc_weixin_erweima());
			var res;
			get_data.then(duixin_data => {
				res = duixin_data;
				if(res.data.code) {
					
					var weixinid = res.data.data;
					this.weixinid = weixinid;
					//console.log(weixinid);
					this.pcweixinlogin(weixinid);
				} else {
					uni.showToast({
						icon: 'none',
						title: '获取失败，请稍后重试'
					});
				}
			})
		},
        // 加载www全局数据
        async loadWwwData() {
            try {
                // 方式1：使用全局挂载的方法
                const data = await this.$getWwwData();
                this.wwwData = data;
				//传到父组件
				this.$emit('www-data', data);
               // //console.log('通过全局挂载方法获取到的www数据:', data);
                
                // 方式2：直接从缓存中获取（如果只需要缓存数据而不需要最新数据）
                // const cachedData = uni.getStorageSync('www');
                // if (cachedData) {
                //     this.wwwData = cachedData;
                //     //console.log('从缓存获取到的www数据:', cachedData);
                // }
            } catch (error) {
                //console.error('获取www数据失败:', error);
                // 出错时尝试从缓存获取数据
                const cachedData = uni.getStorageSync('www');
                if (cachedData) {
                    this.wwwData = cachedData;
                   // //console.log('从缓存获取到的www数据:', cachedData);
                }
            }
        },
		/*checkLoginStatus() {
  		  this.yidenglu = (this.$store.state.memberuid && this.$store.state.keycode) ? 1 : 0;
  		},*/
		  checkCurrentPage() {
            const pages = getCurrentPages();
            if (pages.length) {
                const currentPage = pages[pages.length - 1];
                // 修改数据属性而不是计算属性
                this.isHomePageData = currentPage.route === 'pages/index/index' || 
                                     currentPage.route === 'pages/zhishi/index' ||
                                     currentPage.route === 'pages/yingyong/index' ||
                                     currentPage.route === 'pages/yingyong/chajian' ||
                                     currentPage.route === 'pages/yingyong/fuwu' ||
                                     currentPage.route === 'pages/yingyong/muban' ||
                                     currentPage.route === 'pages/yingyong/zujian' ||
                                     currentPage.route === 'pages/wenda/index' ||
                                     currentPage.route === 'pages/shouce/index' ||
                                     currentPage.route === 'pages/sou/index';
            }
        },
    	//首页
    	shouye(){
			// 触发父组件的清理音频方法
			this.$emit('clear-audio');
    		uni.switchTab({
    			url: '/pages/index/index',
				success: () => {
  				  this.$forceUpdate(); // 强制更新视图
  				},
    			fail: (err) => {
    				console.error('跳转失败:', err)
    			}
    		})
    	},
		//消息
    	xiaoxi(){
			// 触发父组件的清理音频方法
			this.$emit('clear-audio');
    		uni.switchTab({
    			url: '/pages/xiaoxi/index',
				success: () => {
  				  this.$forceUpdate(); // 强制更新视图
  				},
    			fail: (err) => {
    				console.error('跳转失败:', err)
    			}
    		})
    	},
		open() {
			this.$refs.popup.open();
		},
		//跳转click_daohang
		click_daohang(e){
			if(e.id > 4){
				this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
				this.$emit('denglu-fabu');
			}
			//打印
			this.$emit('leixing',e.id);
			////console.log('id:',e.id);
			/*if(e.index==0){
				// 跳转到首页
				// 跳转到首页
				uni.switchTab({
        		    url: '/pages/index/index',
        		    success: () => {
        		        this.$forceUpdate();
        		    },
        		    fail: (err) => {
        		        console.error('跳转失败:', err);
        		    }
        		});

			} else if(e.index==1){
				// 跳转到圈子
				uni.switchTab({
        		    url: e.url,
        		    success: () => {
        		        this.$forceUpdate();
        		    },
        		    fail: (err) => {
        		        console.error('跳转失败:', err);
        		    }
        		});
			} else if(e.index==2){
				// 跳转到小知识
				uni.reLaunch({
        		    url: '/pages/zhishi/index',
        		    success: () => {
        		        this.$forceUpdate();
        		    },
        		    fail: (err) => {
        		        console.error('跳转失败:', err);
        		    }
        		});
			} else if(e.index==1){
				// 跳转到小知识
				uni.reLaunch({
        		    url: '/pages/quan/index',
        		    success: () => {
        		        this.$forceUpdate();
        		    },
        		    fail: (err) => {
        		        console.error('跳转失败:', err);
        		    }
        		});
			} else {
				this.xuanzezhi=e.index;
				uni.navigateTo({
				    url: e.url,
				    success: () => {
				        this.$forceUpdate();
				    },
				    fail: (err) => {
				        console.error('跳转失败:', err);
				    }
				});
			}*/

		},
		sousuo_daohang(e){
			if(e.index==0){
				// 跳转到首页
				uni.switchTab({
				    url: '/pages/index/index',
				    success: () => {
				        this.$forceUpdate();
				    },
				    fail: (err) => {
				        console.error('跳转失败:', err);
				    }
				});
	        }
		},
		change(e) {
            if(e.show) {
      		  document.body.classList.add('popup-open')
      		  document.documentElement.classList.add('popup-open')
      		} else {
      		  document.body.classList.remove('popup-open')
      		  document.documentElement.classList.remove('popup-open')
      		  // 强制触发重绘
      		  setTimeout(() => {
      		    document.body.style.overflow = ''
      		    document.documentElement.style.overflow = ''
      		  }, 50)
      		}
        },
		dengluzhi(){
			this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
		},
		handleDengluClick(e) {
			// 改为触发事件通知父组件
            this.$emit('update-dengluxianshi', 0);
            // 只有点击denglu区域（非denglu_2）才关闭
            // 使用更可靠的方式判断点击目标
			//console.log("点击了denglu区域22")
           // 通过 DOM 查询判断点击位置
		   const clickX = e.detail.x;
            const clickY = e.detail.y;
            const dengluEl = uni.createSelectorQuery().select('.denglu');
            const denglu_2El = uni.createSelectorQuery().select('.denglu_2');
            
            dengluEl.boundingClientRect(dengluRect => {
                denglu_2El.boundingClientRect(denglu2Rect => {
                    const isClickOnDenglu = 
                        clickX >= dengluRect.left && 
                        clickX <= dengluRect.right &&
                        clickY >= dengluRect.top && 
                        clickY <= dengluRect.bottom &&
                        !(clickX >= denglu2Rect.left && 
                          clickX <= denglu2Rect.right &&
                          clickY >= denglu2Rect.top && 
                          clickY <= denglu2Rect.bottom);
                    
                    if (isClickOnDenglu) {
                        this.dengluzhi();
                    }
                }).exec();
            }).exec();    
        },
		noop() {}, // 空方法用于阻止事件冒泡
		getVcode() {
				this.vcodeTime = 60
				this.vcodeTimer = setInterval(() => {
					if (this.vcodeTime > 0) {
						this.vcodeTime--
					} else {
						clearInterval(this.vcodeTimer)
						this.vcodeTimer = null
					}
				}, 1000)
				uni.showToast({
					title: "获取验证码",
					icon: 'none'
				})
			},
			login() {
				uni.showToast({
					title: "登录成功",
					icon: 'none'
				});
				// 登录触发
				this.yidenglu = 1;
				this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
			},
			tuichu(){
				
				uni.showToast({
					title: "退出成功",
					icon: 'success',
					
				})

				uni.removeStorageSync('userInfo');
				uni.removeStorageSync('memberuid');
				uni.removeStorageSync('keycode');
				uni.removeStorageSync('member');
				// 通过 mutations 更新 Vuex 状态
				this.$store.commit('setMember', {});
    			this.$store.commit('setMemberUid', '');
    			this.$store.commit('setKeycode', '');
				//this.yidenglu = 0;
				// 触发退出事件
				this.$emit('logout-success');
				//this.get_tuichu();
			},
			//退出接口
			get_tuichu(){
				var get_data = getRequest(Api.getTuichu());
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						
						
					}
				})

			},
			url(url,id){
				if(id==1){
					////console.log('切换标签',url)
					uni.switchTab({
						url: '/pages/'+url+'/index',
						success: () => {
						this.$forceUpdate(); // 强制更新视图
						}
					});

				} else {
					uni.navigateTo({
						url: '/pages/'+url+'/index',
						success: () => {
						this.$forceUpdate(); // 强制更新视图
						}
					});
				}
				
			},
			shezhi_url(){
				uni.navigateTo({
					url: '/pages/u/shezhi',
					success: () => {
					this.$forceUpdate(); // 强制更新视图
					}
				});
			},
			// 用户注册
			async zhuce(){
				try {
					var d = this;
					
					if(!d.xieyizhi || d.xieyizhi.length === 0) {
						
        			    uni.showToast({
        			        title: '请先同意用户协议和隐私协议',
        			        icon: 'none'
        			    });
        			    return;
        			}

					var username = d.yonghu.username; //账号
					var name = d.yonghu.name; //账号
					var password = d.yonghu.password; //密码
					var password2 = d.yonghu.password; //确认密码2
					var email = d.yonghu.email; //邮箱可选
					var phone = d.yonghu.phone; //手机号码可选
					var protocol = d.xieyizhi[0]; //是否同意协议
					var vcode = d.yonghu.vcode; //验证码
					//var datas = "is_ajax=1&data[password]="+password+"&data[password2]="+password2+"&is_protocol="+protocol;
					var datas = "&is_ajax=1";
					if(username){
						datas += '&data[username]=' + username;
					}
					if(phone){
						datas += '&data[phone]=' + phone;
					}
					if(email){
						datas += '&data[email]=' + email;
					}
					if(name){
						datas += '&data[name]=' + name;
					}
					if(vcode){
						datas += '&sms=' + vcode;
					}
					//postYonghuRegiste
					/*const params = {
    				    is_ajax: 1,
    				    is_protocol: protocol,
    				    data: {
							...(name && {username: name}),
							...(username && {username: username}), // 只有username有值时才包含在data中
							...(email && {email: email}), // 只有email有值时才包含在data中
							...(phone && {phone: phone}), // 同样处理phone
    					    password: password,
    					    password2: password2
    					},
    				    
    				    
    				};*/
					var post_data = postRequest(Api.postYonghuLogin_sms(),datas);
					var res;
					post_data.then(response => {
						res = response;
						if(res.data.code) {	
							uni.showToast({
								title: '操作成功',
								icon: 'success',
								duration: 2000
							});
							 // 保存用户信息到本地storage
							//uni.setStorageSync('userInfo', response.data.data.member.auth);
							uni.setStorageSync('memberuid', response.data.data.member && response.data.data.member.id);
							uni.setStorageSync('member', response.data.data.member);
							uni.setStorageSync('keycode', response.data.data.auth);

							this.$store.commit('setMember', response.data.data.member);
    						this.$store.commit('setMemberUid', response.data.data.member.id);
    						this.$store.commit('setKeycode', response.data.data.auth);
							//this.yidenglu = 1;
							this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
							this.$emit('login-success'); // 添加这行
							//头像
							this.touxiang = response.data.data.member && response.data.data.member.avatar;
							//昵称
							if(!response.data.data.member && response.data.data.member.name){
								this.name1 = response.data.data.member && response.data.data.member.username;

							} else {
								//昵称
								this.name1 = response.data.data.member && response.data.data.member.name;
							}
							//关闭弹出
							//登录跳转到登录页面
							//uni.reLaunch({ url: "/pages/index/index" });
						} else {
							uni.showToast({
								icon: 'none',
								title: response.data.msg
							});
						}
					})
				} catch (error) {
					console.error(error);
					uni.showToast({
						icon: 'none',
						title: '注册失败，请稍后重试'
					});
				}
			},
			// 登录认证码
			postRenzhengma(){
				var d = this;
				var phone = d.yonghu.phone; //手机号码可选
				
				// 判断 手机号不能为空
				// 添加手机号非空验证
				if(!phone) {
    			    uni.showToast({
    			        title: '请输入手机号码',
    			        icon: 'none'
    			    });
    			    return;
    			}
			
    			// 添加手机号格式验证
    			if(!/^1[3-9]\d{9}$/.test(phone)) {
    			    uni.showToast({
    			        title: '请输入正确的手机号码',
    			        icon: 'none'
    			    });
    			    return;
    			}
				this.vcodeTime = 60
				this.vcodeTimer = setInterval(() => {
					if (this.vcodeTime > 0) {
						this.vcodeTime--
					} else {
						clearInterval(this.vcodeTimer)
						this.vcodeTimer = null
					}
				}, 1000)
				uni.showToast({
					title: "获取验证码",
					icon: 'none'
				})
				var datas = '&id=' + phone;
				
				
				var post_data = getRequest(Api.postRenzhengma(phone),datas);
				var res;
				post_data.then(response => {
					res = response;
					if(res.data.code) {	
						uni.showToast({
							title: '发送成功',
							icon: 'success',
							duration: 2000
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: response.data.msg
						});
					}
				})
			},
			// 用户注册
			async denglu_data(){
				try {
					var d = this;
					/*if(!d.xieyizhi || d.xieyizhi.length === 0) {
						
        			    uni.showToast({
        			        title: '请先同意用户协议和隐私协议',
        			        icon: 'none'
        			    });
        			    return;
        			}*/
					var username = d.yonghu.username; //账号
					var name = d.yonghu.name; //账号
					var password = d.yonghu.password; //密码
					var password2 = d.yonghu.password; //确认密码2
					var email = d.yonghu.email; //邮箱可选
					var phone = d.yonghu.phone; //手机号码可选
					var protocol = d.xieyizhi[0]; //是否同意协议
					//检查d.xieyizhi是否打勾

					var datas = "is_ajax=1&data[password]="+password+"&is_protocol="+protocol;
					if(username){
						datas += '&data[username]=' + username;
					}
					if(phone){
						datas += '&data[phone]=' + phone;
					}
					if(email){
						datas += '&data[email]=' + email;
					}
					if(name){
						datas += '&data[name]=' + name;
					}
					var post_data = postRequest(Api.postYonghuLogin(),datas);
					var res;
					post_data.then(response => {
						res = response;
						if(res.data.code) {	
							uni.showToast({
								title: '操作成功',
								icon: 'success',
								duration: 2000
							});
							 // 保存用户信息到本地storage
							//uni.setStorageSync('userInfo', response.data.data.member.auth);
							uni.setStorageSync('memberuid', response.data.data.member.uid);
							uni.setStorageSync('member', response.data.data.member);
							uni.setStorageSync('keycode', response.data.data.member.auth);
							this.$store.commit('setMember', response.data.data.member);
    						this.$store.commit('setMemberUid', response.data.data.member.uid);
    						this.$store.commit('setKeycode', response.data.data.auth);
							//头像
							this.touxiang = response.data.data.member.avatar;
							//昵称
							if(!response.data.data.member.name){
								this.name1 = response.data.data.member.username;

							} else {
								//昵称
								this.name1 = response.data.data.member.name;
							}
							
							//this.yidenglu = 1;
							this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
							this.$emit('login-success'); // 添加这行
							//关闭弹出
							//登录跳转到登录页面
							//uni.reLaunch({ url: "/pages/index/index" });
						} else {
							uni.showToast({
								icon: 'none',
								title: response.data.msg
							});
						}
					})
				} catch (error) {
					console.error(error);
					uni.showToast({
						icon: 'none',
						title: '注册失败，请稍后重试'
					});
				}
			},

			toPact(){
				console.log("协议");
			},
			pactChange(){
				this.pactChecked = !this.pactChecked;  // 切换勾选状态
				this.xieyizhi = this.pactChecked ? [1] : [];
			},
			exitlogin() {
				uni.removeStorageSync('userInfo');
				uni.removeStorageSync('memberuid');
				uni.removeStorageSync('keycode');
				uni.removeStorageSync('member');
				uni.reLaunch({ url: '/pages/login/login'})
			},
			daohang_click(index){
				console.log(index);
				this.$emit('daohang_click', index);
			},
			// 获取 url 的id参数
			getUrlId() {
				// 获取当前页面的URL
				const pages = getCurrentPages();
				if (pages.length > 0) {
					const currentPage = pages[pages.length - 1];
					const url = currentPage.route + '?' + (currentPage.options ? Object.keys(currentPage.options).map(key => `${key}=${currentPage.options[key]}`).join('&') : '');
					
					// 解析URL参数
					const params = {};
					const paramStr = url.split('?')[1];
					if (paramStr) {
						paramStr.split('&').forEach(param => {
							const [key, value] = param.split('=');
							if (key === 'id') {
								this.id = value;
							}
						});
					}
				}
			},
			// 发布
			fabu(){
				////console.log('尝试跳转到发布页面，id值为:', this.id);
				// 检查id是否存在
				if (!this.id) {
					getApp().globalData.currentId = '';
					getApp().globalData.title = '';
				} else {
					getApp().globalData.currentId = this.id;
					getApp().globalData.title = this.title;

				}
				// 存储id到全局变量(switchTab不支持URL传参)
				
				
				// 使用switchTab跳转tabbar页面
				uni.switchTab({
					url: '/pages/quan/index',
					success: () => {
					  ////console.log('跳转成功');
					  this.$forceUpdate(); // 强制更新视图
					},
					fail: (err) => {
					  console.error('跳转失败:', err);
					  uni.showToast({
							title: '跳转失败，请重试',
							icon: 'none'
					  });
					}
				});
			},
			geren(uid){
				uni.navigateTo({
					url: '/pages/u/index?uid='+uid,
					success: () => {
					this.$forceUpdate(); // 强制更新视图
					}
				});
			},
			getU(){
				uni.switchTab({
					url: '/pages/u/u',
					success: () => {
					this.$forceUpdate(); // 强制更新视图
					}
				});
			},
			get_uid(){
				// 获取用户uid
				var uid = this.uid;
				var code = this.$store.state.memberuid && this.$store.state.keycode;
				// get接口 getUID
				var get_data = getRequest(Api.getUID(uid,code));
				var res;
					get_data.then(response => {
						res = response;
						if(res.data.code == 1){
							this.uiddata = res.data.data;
							//把 this.uiddata 到 父组件
							this.$emit('uiddata', this.uiddata);
							////console.log('用户数据',this.uiddata);
							this.touxiang = res.data.data.avatar;
							//昵称
							if(!res.data.data.name){
								this.name1 = res.data.data.username;
							} else {
								//昵称
								this.name1 = res.data.data.name;
							}
						}
					}).catch(error => {
						console.error(error);
					})
			},
			go_shouye(){
				uni.switchTab({
					url: '/pages/index/index',
					success: () => {
					this.$forceUpdate(); // 强制更新视图
					}
				});
			},
			go_xiaoxi(){
				uni.switchTab({
					url: '/pages/xiaoxi/index',
					success: () => {
					this.$forceUpdate(); // 强制更新视图
					}
				});
			},
			//注册项目
			zhucexiangmu(){  
				var duixin = this;
				var postYonghuzhuceRequest = getRequest(Api.postYonghuRegiste());
				postYonghuzhuceRequest.then(response => {
					if (response.data.code == 1 && response.data.data && response.data.data.register) {
					    // 正确获取注册选项数据
						duixin.zhucexuanxiang = response.data.data.register.field || [];
						// 打印注册选项数据
						///console.log('注册选项数据:', duixin.zhucexuanxiang);
						// 判断数组中是否包含'phone'元素						
						if (Array.isArray(duixin.zhucexuanxiang) && duixin.zhucexuanxiang.includes('email')) {
							duixin.loginType = 2;
							duixin.email = 1;
							console.log('未检测到phone字段，设置loginType为2');
						} else {
							duixin.loginType = 2;
							duixin.email = 0;
						}

						if (Array.isArray(duixin.zhucexuanxiang) && duixin.zhucexuanxiang.includes('username')) {
							duixin.loginType = 2;
							duixin.username = 1;
							//console.log('未检测到phone字段，设置loginType为2');
						} else {
							duixin.loginType = 2;
							duixin.username = 0;
						}
						// 判断数组中是否包含'phone'元素	
						if(Array.isArray(duixin.zhucexuanxiang) && duixin.zhucexuanxiang.includes('phone')){
							duixin.loginType = 1;
							duixin.phone = 1;
							//console.log('检测到包含phone字段，设置loginType为1');
						} else {
							duixin.loginType = 2;
						    duixin.phone = 0;
						}
						// 判断数组中是否包含'code'元素	
						if(response.data.data && response.data.data.register.code){
							duixin.code = 1;
							//console.log('检测到需要验证码');
						} else {
							duixin.code = 0;
							//console.log('不需要验证码');
						}
					} else {
						//console.log('获取注册选项失败或数据格式不正确');
						duixin.zhucexuanxiang = [];
						duixin.loginType = 2;
					}
				}).catch(error => {
					console.error('获取注册选项请求失败:', error);
					duixin.zhucexuanxiang = [];
					duixin.loginType = 2;
				});
			},
			//新用户注册
			async zhuce_data(){
				try {
					var d = this;
					var username = d.yonghu.username; //账号
					var name = d.yonghu.name; //账号
					var password = d.yonghu.password; //密码
					var password2 = d.yonghu.password; //确认密码2
					var email = d.yonghu.email; //邮箱可选
					var phone = d.yonghu.phone; //手机号码可选
					var code = d.yonghu.code; //认证码
					var protocol = d.xieyizhi[0]; //是否同意协议
					// 验证密码不能为空
					if (!password) {
						uni.showToast({
							title: '请输入密码',
							icon: 'none'
						});
						return;
					}
					if(this.code==1 && !code){
						uni.showToast({
							title: '请输入验证码',
							icon: 'none'
						});
						return;
					}
					var datas = "is_ajax=1&data[password]="+password+"&is_protocol="+protocol+'&data[password2]='+password;
						if(username){
							datas += '&data[username]=' + username;
						}
						if(phone){
							datas += '&data[phone]=' + phone;
						}
						if(email){
							datas += '&data[email]=' + email;
						}
						if(name){
							datas += '&data[name]=' + name;
						}
						if(this.code==1){
							datas += '&data[code]=' + code;
						}
						var post_data = postRequest(Api.postYonghuRegiste(),datas);
						var res;
						post_data.then(response => {
							res = response;
							if(res.data.code) {	
								uni.showToast({
									title: '注册成功',
									icon: 'success',
									duration: 2000
								});
								 // 保存用户信息到本地storage
								//uni.setStorageSync('userInfo', response.data.data.member.auth);
								uni.setStorageSync('memberuid', response.data.data && response.data.data.member && response.data.data.member.uid);
								uni.setStorageSync('member', response.data.data && response.data.data.member && response.data.data.member);
								uni.setStorageSync('keycode', response.data.data && response.data.data.member && response.data.data.member.auth);
								this.$store.commit('setMember', response.data.data && response.data.data.member);
								this.$store.commit('setMemberUid', response.data.data && response.data.data.member && response.data.data.member.uid);
								this.$store.commit('setKeycode', response.data.data && response.data.data.member && response.data.data.member.auth);
								//头像
								this.touxiang = response.data.data.member.avatar;
								//昵称
								if(!response.data.data.member.name){
									this.name1 = response.data.data.member.username;
					
								} else {
									//昵称
									this.name1 = response.data.data.member.name;
								}
								
								//this.yidenglu = 1;
								this.denglu_xianshi = this.denglu_xianshi === 0 ? 1 : 0;
								this.$emit('login-success'); // 添加这行
								//关闭弹出
								//登录跳转到登录页面
								//uni.reLaunch({ url: "/pages/index/index" });
							} else {
								uni.showToast({
									icon: 'none',
									title: response.data.msg
								});
							}
						})
					} catch (error) {
						console.error(error);
						uni.showToast({
							icon: 'none',
							title: '注册失败，请稍后重试'
						});
					}
				
			},
			//获取注册认证码
			getRenzhengma(){
				//console.log('获取注册认证码');
				// 添加时间戳防止缓存
				const timestamp = new Date().getTime();
				this.get_rzm = Api.getZhuceRenzhengma() + '?t=' + timestamp;
				//console.log('更新后的认证码URL:', this.get_rzm);
			},
    }
}
</script>

<style scoped lang="scss">
	.denglu {
		width: 100%;
	    height: 100%;
	    z-index: 100000;
		left: 0;
	  top: 0;
	  position: fixed;
	  background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
	  
	}

	.denglu_2 {
	  width: 1200rpx;
	  height: 900rpx;
	  position: fixed;
	  left: 50%;
	  top: 50%;
	  transform: translate(-50%, -50%);
	  background-color: rgba(255, 255, 255, 1); /* 半透明黑色背景 */
	  border-radius: 20rpx; /* 可选：添加圆角 */
	}
	.huise {
		background-color: #f5f5f5;
		height: 900rpx;
		border-radius: 0rpx 20rpx 20rpx 0 ; /* 可选：添加圆角 */
	}
	.d-erweima {
		width: 380rpx;
		height: 380rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		/* 左右居中 */
		margin-left: auto;
		margin-right: auto;
		/* 上下居中 */
		margin-top: auto;
		margin-bottom: auto;
		/* 居中 */
	}
	.title {
		padding-top: 30rpx;
		padding-bottom: 50rpx;
		view {
			padding-left: 64rpx;
			font-size: 48rpx;
			font-weight: 700;
			color: #383838;
		}
	}
	.form {
			flex: 1;
			padding: 0 64rpx;

			.tab {
				display: flex;
				align-items: center;
				justify-content: space-between;
				/*background-color: #ecf1fb;*/
				height: 100rpx;
				/*background: linear-gradient(180deg, #e3ebf9 0%, #ffffff 100%);*/

				view {
					width: 340rpx;
					line-height: 100rpx;
					text-align: center;
					color: #9e9e9e;
					position: relative;
				}

				view::after {
					content: '';
					width: 50rpx;
					height: 8rpx;
					display: block;
					background-color: #16afa8;
					border-radius: 4rpx;
					position: absolute;
					left: 50%;
					bottom: 14rpx;
					transform: translateX(-50%);
					opacity: 0;
				}

				view.select {
					/*background-color: #fff;*/
					color: #06adb3;
				}

				view.type1.select {
					border-radius: 0 40rpx 0 0;
				}

				view.type2.select {
					border-radius: 40rpx 0 0;
				}

				view.select::after {
					opacity: 1;
				}
			}

			.inputs {
				margin-bottom: 30rpx;

				>view {
					height: 96rpx;
					border-bottom: 1rpx solid #cdcdcd;
					display: flex;
					align-items: center;

					input {
						flex: 1;
					}
				}

				.account {
					margin-bottom: 48rpx;

					view {
						padding-right: 20rpx;
						margin-right: 20rpx;
						border-right: 1rpx solid #cdcdcd;
					}
				}

				.vcode {
					text {
						text-wrap: nowrap;
					}
				}
			}

			.button {
				view {
					line-height: 96rpx;
					border-radius: 20rpx;
					text-align: center;
					font-size: 32rpx;
					color: #ffffff;
					background-color: #16afa8;
				}
			}

			.tip {
				font-size: 28rpx;
				text-align: center;
				margin-top: 30rpx;
				color: #808080;
			}
		}
		.pact {
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 70rpx;
			font-size: 24rpx;

			text {
				color: #3ba662;
			}

			radio {
				:deep(.uni-radio-input) {
					border: 1rpx solid #3ba662;
				}

				transform:scale(0.6)
			}
		}
		.d-xiala-0 {
		  position: relative;
		  display: inline-block;
		  
		  &:hover {
  			  .d-xiala-1 {
  			    display: block;
  			  }
  			}
		}
		.d-xiala-1 {
			/*margin: 30rpx;*/
		  position: absolute;
		  top: 100%;
		  left: 0;
		  background-color: #fff;
		  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
		  border-radius: 8rpx;
		  padding: 5rpx 16rpx;
		  z-index: 1000;
		  min-width: 200rpx;
          /*display: block;*/ /* 修改为block */
		  white-space: nowrap;

		 /* &.show {
		    display: block;
		  }*/
		}
		.d-denglu {
		  position: relative;
		}
		/* #ifdef APP || H5 */
		.d-kuan-baifen-70-cm {
			width: 100%;
		}
		/* #endif */
		/* #ifdef MP */
		.d-kuan-baifen-70-cm {
			width: 70%;
		}
		/* #endif */
		.impowerBox .qrcode {width: 150px;}
		.impowerBox .title {display: none;}
		.impowerBox .info {width: 150px;}
		.status_icon {display: none}
		.impowerBox .status {text-align: center;}
</style>